<?php
namespace App\Repositories\Backend;

use App\Models\Doctor;
use Illuminate\Support\Facades\Auth;

class DoctorRepository extends CommonRepository
{
    public function __construct(Doctor $doctor)
    {
        parent::__construct($doctor);
    }

    /**
     * 列表
     * @param  array $input 查询条件
     * @return object
     */
    public function getLists($input)
    {
        $default_search = [
            'filter' => ['id' , 'subject_id', 'face_image', 'doctor_name', 'tags','easy_adepts', 'detail_adepts', 'consult_number' , 'registration_number' , 'order'],
            'sort'   => [
                'order' => 'asc',
            ]
        ];
        $search = $this->parseParams($default_search, $input);
        return $this->model->parseWheres($search)->paginate();
    }

    /**
     * 新增
     * @param  string   $subject_id          绑定科目id
     * @param  string   $doctor_name         医生名字
     * @param  string   $face_image          医生照片
     * @param  int      $tags                医生标签
     * @param  string   $easy_adepts         简单描述
     * @param  string   $detail_adepts       详细描述
     * @param  string   $consult_number      咨询量
     * @param  string   $registration_number 挂号量
     * @param  string   $order               排序
     * @return object
     */
    public function create($subject_id, $doctor_name, $face_image, $tags,$easy_adepts, $detail_adepts, $consult_number, $registration_number, $order)
    {
        $result = $this->model->create([
            'subject_id' => $subject_id,
            'doctor_name'        => $doctor_name,
            'face_image'        => $face_image,
            'tags'               => $tags,
            'easy_adepts'        => $easy_adepts,
            'detail_adepts'      => $detail_adepts,
            'consult_number'     => $consult_number,
            'registration_number'=> $registration_number,
            'order'              => $order,
        ]);

        return $result;
    }


    /**
     * 编辑
     * @param  int $id
     * @param  string   $subject_id          绑定科目id
     * @param  string   $doctor_name         医生名字
     * @param  string   $face_image          医生照片
     * @param  int      $tags                医生标签
     * @param  string   $easy_adepts         简单描述
     * @param  string   $detail_adepts       详细描述
     * @param  string   $consult_number      咨询量
     * @param  string   $registration_number 挂号量
     * @param  string   $order               排序
     * @return object
     */
    public function update($id, $doctor_name, $face_image, $tags,$easy_adepts, $detail_adepts, $consult_number, $registration_number, $order)
    {
        $result = $this->model->where('id', $id)->update([
            'doctor_name'        => $doctor_name,
            'face_image'        => $face_image,
            'tags'               => $tags,
            'easy_adepts'        => $easy_adepts,
            'detail_adepts'      => $detail_adepts,
            'consult_number'     => $consult_number,
            'registration_number'=> $registration_number,
            'order'              => $order,
        ]);

        return $result;
    }

    public function destroy($id)
    {

        return $this->deleteById($id);
    }



    public function doctordata($input)
    {
        $default_search = [
            'filter' => ['id' , 'subject_name', 'comment', 'subject_image1','subject_image2' , 'order','status','created_at'],
            'sort'   => [
                'order' => 'asc',
            ],
        ];
        $search = $this->parseParams($default_search, $input);
        return $this->model->where($input)->paginate();
    }


    public function doctorlist($input)
    {


        return $this->model->all(['id','subject_id','doctor_name']);
    }

}
